package edu.scau.mis.cloth.service.impl;

import edu.scau.mis.cloth.dao.GsClothesDao;
import edu.scau.mis.cloth.entity.GsClothes;
import edu.scau.mis.cloth.service.GsClothesService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (GsClothes)表服务实现类
 *
 * @author makejava
 * @since 2022-03-09 20:39:26
 */
@Service("gsClothesService")
public class GsClothesServiceImpl implements GsClothesService {
    @Resource
    private GsClothesDao gsClothesDao;

    public GsClothes queryByAttrsId(Integer id) {
        return this.gsClothesDao.queryByAttrsId(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public List<GsClothes> queryById(Integer id) {
        return this.gsClothesDao.queryById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param clCategoryId 主键
     * @return 实例对象
     */
    @Override
    public List<GsClothes> queryByCate(Integer clCategoryId) {
        return this.gsClothesDao.queryByCate(clCategoryId);
    }

    /**
     * 查询指定行
     *
     * @param gsClothes 筛选条件
     * @return 查询结果
     */
    @Override
    public List<GsClothes> queryAll(GsClothes gsClothes) {
        return this.gsClothesDao.queryAll(gsClothes);
    }


    public GsClothes queryId(Integer clId){
        return gsClothesDao.queryId(clId);
    }

    /**
     * 分页查询
     *
     * @param gsClothes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<GsClothes> queryByPage(GsClothes gsClothes, PageRequest pageRequest) {
        long total = this.gsClothesDao.count(gsClothes);
        return new PageImpl<>(this.gsClothesDao.queryAllByLimit(gsClothes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param gsClothes 实例对象
     * @return 实例对象
     */
    @Override
    public GsClothes insert(GsClothes gsClothes) {
        this.gsClothesDao.insert(gsClothes);
        return gsClothes;
    }

    /**
     * 修改数据
     *
     * @param gsClothes 实例对象
     * @return 实例对象
     */
    @Override
    public GsClothes update(GsClothes gsClothes) {
        this.gsClothesDao.update(gsClothes);
        return gsClothes;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.gsClothesDao.deleteById(id) > 0;
    }

    @Override
    public List<Map<String,Object>> checkInventoryById(Integer id) {
        return gsClothesDao.checkInventoryById(id);
    }

    @Override
    public List<Map<String, Object>> checkInventoryByCategory() {
        return gsClothesDao.checkInventoryByCategory();
    }
    @Override
    public List<Map<String,Object>> checkInventoryBySize(){
        return gsClothesDao.checkInventoryBySize();
    }

}
